<include file="public/shop_header"/>

<body>

<style type="text/css">
  #lie_biao{
    text-align: center;
    font-size: 18px;
    margin-top: 10px;
  }
  .lie_vi{
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
  }
  .lie_user{
    margin-left: 2%;
    width: 15%;
    text-align: center;
  }
  .user_img{
    width: 20px;
    height: 20px;
  }
  .name_vi{
    width: 65%;
  }
  .user_name{
    font-size: 18px;
  }
  .user_time{
    font-size: 18px;
  }
  .img_img{
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 32%;
  }
  .content_vi{
    margin-top: 10px;
    margin-left: 2%;
    width: 96%;
    padding-bottom: 10px;
    font-size: 18px;
  }
  .divKong{
    height: 10px;
    width: 100%;
    background-color: #e3e3e3;
  }

</style>

<!--详情图切换-->
<div class="pProduct-detaSider">
  <ul class="swiper-wrapper clearfix">

    <li class="swiper-slide">
      <img src="{$goodsInfo.original_img}">
    </li>
    <volist name="$goodsInfo['image']" id="image">
      <li class="swiper-slide">
        <img src="{$image}">
      </li>
    </volist>

  </ul>
  <div class="iboxt">
    <h3 class="t">{$goodsInfo.goods_name}</h3>
    <div class="c">
      {$goodsInfo.goods_remark}
    </div>
    <div class="f">
      <span class="price">￥<strong id="price">{:strtotime($user.vip_time) > time() && $user.vip ? $goodsInfo.vip_price : $goodsInfo.shop_price }</strong></span><del>￥{$goodsInfo.original_price}</del>
    </div>
  </div>
  <div class="swiper-pagination">
  </div>
</div>
<!--详情图切换 End--> 

<!--main-->
<div class="cpMain">

  <!--<div class="pProduct-detaPara clearfix">-->
    <!--<a href="javascript:;"><span class="cn">商品参数</span></a>-->
  <!--</div>-->
  <!--图文详情-->
  <div class="pProduct-detaGrap-tit">
    图文详情
  </div>
  <div class="pProduct-detaGrap-info">
    {:html_entity_decode($goodsInfo['content'])}
  </div>
  <!--图文详情 End-->

  <div class="pProduct-detaGrap-tit">
    评论
  </div>
  <div class="pProduct-detaGrap-info">
    <volist name="$evaluate" id="vo">
        <div class="lie_vi">
          <div class="lie_user">
            <img class="user_img" src="{$vo.head_img}" >
          </div>
          <div class="name_vi">
            <div class="user_name">{$vo.username}</div>
            <div class="user_time"><if $vo.evaluation_time gt 0>{:date('Y-m-d H:i:s',$vo.evaluation_time)} <else /> {:date('Y-m-d H:i:s')} </if></div>


          </div>
          <div class="img_img">
            <for start="0" end="$vo.level">
              <img class="user_img" src="__PUBLIC__/images/allsc1.png" >
            </for>
          </div>
        </div>
        <div class="content_vi">
          {$vo.content}
        </div>
        <div class="divKong"></div>
    </volist>

  </div>


</div>
<!--main End--> 

<!--联系客服-->
<div class="pProduct-detaButton clearfix">
  <a href="tel:{$config.index_phone}" class="cust fl"> <i class="iconfont">&#xe600;</i>
    <p class="tit">联系客服</p>
  </a>
  <div class="opera fr">
    <a href="javascript:;" class="o-btn" onclick="add_cart()">加入购物车</a> <a href="javascript:;" class="o-btn go-buy">立即购买</a>
  </div>
</div>
<!--联系客服 End--> 

<!--立即购买弹出层-->
<div class="pProduct-pupMarsk">
</div>
<div class="pProduct-pup" id="pProduct-pup">
  <a href="javascript:;" class="close iconfont">&#xe6c5;</a>
  <div class="pProduct-pupHead clearfix">
    <div class="pic">
      <img src="{$goodsInfo.original_img}">
    </div>
    <div class="name">
      {$goodsInfo.goods_name}
    </div>
    <div class="price clearfix">
      <span class="sale">￥<strong id="price1">{:strtotime($user.vip_time) > time() && $user.vip ? $goodsInfo.vip_price : $goodsInfo.shop_price }</strong></span> <del>￥{$goodsInfo.original_price}</del>
    </div>
  </div>
  <!--规格-->
  <div class="pProduct-pupSpec">
    <div class="dt">
      规格
    </div>
    <div class="dd clearfix">
      <foreach name="$goodsInfo.spec" item="v1" key="k1">
        <foreach name="v1" item="v2" key="k2">
          <a href="javascript:;" class="item" data-id="{$v2.item_id}">{$v2.item}</a>
        </foreach>
      </foreach>
    </div>
  </div>
  <!--规格 End--> 
  <!--数量-->
  <div class="pProduct-pupAmount clearfix">
    <div class="dt">
      数量
    </div>
    <div class="dd fr">
      <div class="quantity clearfix">
        <a class="decrease iconfont"  href="javascript:void(0)"  id="reduce">&#xe6fd;</a>
          <input type="tel" class="inpt" size="4" value="1" id="num" data-spec-id="" data-id="{$goodsInfo.goods_id}" disabled>
        <a class="increase iconfont"   href="javascript:void(0)" id="add">&#xe71b;</a>
      </div>
    </div>
  </div>
  <!--数量 End-->
  <div class="pProduct-pupButton">
    <a href="javascript:;" class="btn" onclick="confirm()">确   定</a>
  </div>
</div>
<!--立即购买弹出层 End-->
<script type="text/javascript">
    //获取规格价格
    function goods_price(spec_goods_price,spec_key){
        if(spec_goods_price != null && spec_goods_price !=''){
            var goods_price =  '{$vip}' == 1  ? spec_goods_price[spec_key]['vip_price'] : spec_goods_price[spec_key]['price'];

          var store_count = spec_goods_price[spec_key]['store_count'];
            // console.log(spec_key);
        }
        console.log(goods_price)
        $('#price').html(goods_price);
        $('#price1').html(goods_price);
        $('#num').attr('data-max',store_count);
        $('#num').attr('data-spec-id',spec_key);
    }

    $(function () {
        $(".pProduct-pupSpec .dd .item").click(function(){
            $(this).toggleClass("selected").siblings().removeClass("selected");
            var spec_key = $(this).attr('data-id');
            goods_price({$goodsInfo.spec_goods_price},spec_key);
        });



        //数量增加
        $("#add").click(function () {
            var goods_store_count = $('#num').attr('data-max'); //库存
            if (goods_store_count == "undefined"){
                goods_store_count = "{$goodsInfo.store_count}"
            }
            var eleInput = $("#num");
            var num_count = eleInput.val();//获取目前的数量

            if (parseInt(num_count) < parseInt(goods_store_count)){
                eleInput.val(parseInt(eleInput.val()) + 1);
            }
            return false;
            //console.log($("#num").val());
        });



        //数量减少
        $("#reduce").click(function () {
            var goods_store_count = $('#num').attr('data-max'); //库存
            if (goods_store_count == "undefined"){
                goods_store_count = "{$goodsInfo.store_count}"
            }
            var eleInput = $("#num");
            var num_count = eleInput.val();//获取目前的数量

            if (num_count >= 2){
                eleInput.val(parseInt(eleInput.val()) - 1); //数量+1
            }
        });
    });

    //加入购物车
    function add_cart() {
        var _this = $('#num');
        var num = _this.val(); //数量
        var goods_id = _this.attr('data-id'); //商品id
        var spec_key = _this.attr('data-spec-id'); //规格id
        $.ajax({
            type : "POST",
            url:"/Home/Cart/ajaxAddCart.html",
            data : {goods_id:goods_id,goods_num:num,goods_spec:spec_key},// 你的formid 搜索表单 序列化提交
            dataType:'json',
            success: function(data){
                if(data.status != 200){
                    layer.msg(data.msg,{icon:2,time:3000},function(){if(data.url){ window.location.href = data.url;}});
                    return false;
                }
                layer.open({
                    content: data.msg,
                    btn: ['再逛逛', '去购物车'],
                    shadeClose: false,
                    yes: function(){
                        layer.closeAll();
                    }, cancel: function(){
                        location.href = "/Home/Cart/index.html";
                    }
                });
            }
        });
    }

    //直接购买
  function confirm(){
      var _this = $('#num');
      var num = _this.val(); //数量
      var goods_id = _this.attr('data-id'); //商品id
      var spec_key = _this.attr('data-spec-id'); //规格id
      $.ajax({
          type : "POST",
          url:"/home/payment/confirm.html",
          data : {goods_id:goods_id,goods_num:num,goods_spec:spec_key},// 你的formid 搜索表单 序列化提交
          dataType:'json',
          success: function(data){
              if(data.status == 200){
                  if(data.url){ window.location.href = data.url;}
              }
          }
      });
  }

</script>

</body>
</html>
